package gframework.bean.table;

import java.awt.Color;
import java.awt.Component;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;

public class GTableCellRenderer extends DefaultTableCellRenderer {

    private Vector<Integer> vAlinhamento = new Vector();

    public Vector<Integer> getAlinhamento() {
        return vAlinhamento;
    }

    public void setAlinhamento(Vector<Integer> vAlinhamento) {
        this.vAlinhamento = vAlinhamento;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
            boolean hasFocus, int row, int column) {

        Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

        if (cell == null) {
            return null;
        }

        if (isSelected) {
            setBackground(UIManager.getColor("Table.selectionBackground"));
        } else {
            if (row % 2 == 0) {
                setBackground(UIManager.getColor("Table.background"));
            } else {
                setBackground(new Color(236, 237, 240));
            }
        }

        setHorizontalAlignment(vAlinhamento.get(column));

        return (Component) cell;
    }
}